class Solution {
    public int[] plusOne(int[] digits) {
        for(int i = digits.length-1; i>=0; i--){
            if(digits[i]<9){
                digits[i] = digits[i]+1;
                return digits;
            }else{
                digits[i]=0;
                if(i==0){
                    int[] newDig = new int[digits.length+1];
                    newDig[0]=1;
                    System.arraycopy(digits,0,newDig, 1, digits.length);
                    return newDig;
                }
            }
        }
        return digits;         
    }
}